<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('welcome_message');
	}
	
	function zend()
	{
		$this->load->library('zend', 'Zend/Service/Flickr');
		// newer versions of CodeIgniter have updated its loader API slightly,
		// we can no longer pass parameters to our library constructors
		// therefore, we should load the library like this:
		// $this->load->library('zend');
		// $this->zend->load('Zend/Service/Flickr');

		$flickr = new Zend_Service_Flickr('5bac67e68288ed3b5a485d3b25aa2317');

		$results = $flickr->tagSearch('php');
		foreach ($results as $result)
		{
			echo $result->title . '<br />';
		}
	}
	
	function zend_db()
	{
		$this->load->library('zend', 'Zend/Db');
		// newer versions of CodeIgniter have updated its loader API slightly,
		// we can no longer pass parameters to our library constructors
		// therefore, we should load the library like this:
		// $this->load->library('zend');
		// $this->zend->load('Zend/Service/Flickr');

		$db = $this->zend->Zend_Db_Adapter_Pdo_Mysql(array(
			'host'     => $db['default']['hostname'],
			'username' => $db['default']['username'],
			'password' => $db['default']['password'],
			'dbname'   => $db['default']['database']
		));
	}
	
	function zend_user()
	{
		$this->load->library('zend', 'Zend/Acl');
		$this->load->library('zend', 'Zend/Acl/Role');
		$this->load->library('zend', 'Zend/Acl/Resource');
		
		$acl = new Zend_Acl();
		
		$acl->addRole(new Zend_Acl_Role('banned'));
		$acl->addRole(new Zend_Acl_Role('member'));
		$acl->addRole(new Zend_Acl_Role('writer'), 'member');
		$acl->addRole(new Zend_Acl_Role('editor'), 'writer');
		$acl->addRole(new Zend_Acl_Role('moderator'), 'editor');
		$acl->addRole(new Zend_Acl_Role('administrator'));
		
		$acl->add(new Zend_Acl_Resource('usercp'));
		$acl->add(new Zend_Acl_Resource('usercp/settings'), 'usercp');
		$acl->add(new Zend_Acl_Resource('usercp/album'), 'usercp');
		$acl->add(new Zend_Acl_Resource('office'));
		$acl->add(new Zend_Acl_Resource('office/users'), 'office');
		$acl->add(new Zend_Acl_Resource('office/news'), 'office');
		
		/*——————————— Baned ———————————*/
		$acl->allow('banned', 'usercp/settings');
		/*——————————– Member ——————————–*/
		$acl->allow('member', 'usercp');
		/*———————————- Writer ———————————*/
		$acl->allow('writer', 'office/news', array('addnew'));
		/*———————————- Editor ———————————-*/
		$acl->allow('editor', 'office/news');
		/*——————————- Moderator ——————————-*/
		$acl->allow('moderator', 'office');
		$acl->deny('moderator', 'office/users');
		/*—————————– Administrator —————————–*/
		$acl->allow('administrator'); // Grant All
		
		$segment_1 = 'office/news';
		$segment_2 = 'addnew';
		if($acl->isAllowed('banned', $segment_1, $segment_2)){
			echo 'allowed.';
		}else{
			echo 'deny!';
		}
	}
	
	function test_template()
	{
		$this->load->library('template');
		$this->template->write_view('content', 'test_template');
		$this->template->render();
	}
	
	function test_table()
	{
		$this->load->library('table');
		
		$data = array(
			array('Name', 'Color', 'Size'),
			array('Fred', 'Blue', 'Small'),
			array('Mary', 'Red', 'Large'),
			array('John', 'Green', 'Medium')
			);
		echo $this->table->generate($data);
		
		
		$this->table->set_heading('Name', 'Color', 'Size');
		$this->table->add_row('Fred', 'Blue', 'Small');
		$this->table->add_row('Mary', 'Red', 'Large');
		$this->table->add_row('John', 'Green', 'Medium');
		echo $this->table->generate();
		
		$tmpl = array (
                    'table_open'          => '<table border="2" cellpadding="10" cellspacing="5">',

                    'heading_row_start'   => '<tr>',
                    'heading_row_end'     => '</tr>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>',

                    'row_start'           => '<tr>',
                    'row_end'             => '</tr>',
                    'cell_start'          => '<td>',
                    'cell_end'            => '</td>',

                    'row_alt_start'       => '<tr>',
                    'row_alt_end'         => '</tr>',
                    'cell_alt_start'      => '<td>',
                    'cell_alt_end'        => '</td>',

                    'table_close'         => '</table>'
		);
		$this->table->set_template($tmpl);
		
		$this->table->set_heading(array('Name', 'Color', 'Size'));
		$this->table->add_row(array('Fred', 'Blue', 'Small'));
		$this->table->add_row(array('Mary', 'Red', 'Large'));
		$this->table->add_row(array('John', 'Green', 'Medium'));
		echo $this->table->generate();
	}
}

/* End of file home.php */
/* Location: ./application/controllers/welcome.php */